package cn.leyaber.hrm.controller;

import cn.leyaber.hrm.Result.Result;
import cn.leyaber.hrm.Result.UpLoadResult;
import cn.leyaber.hrm.serviec.IFileUpLoadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/oss")
public class UpLoadControlle {
    @Autowired
    private IFileUpLoadService fileUpLoadService;

    @PostMapping("/upload")
    @ResponseBody
    public UpLoadResult upload(@RequestParam("file") MultipartFile multipartFile) {
        return this.fileUpLoadService.upload(multipartFile);
    }

    @GetMapping("/download")
    @ResponseBody
    public Result download(@RequestParam("uid") String  uid, HttpServletResponse response){
        return fileUpLoadService.download(uid,response);
    }

    @DeleteMapping("/delete")
    @ResponseBody
    public Result delete(@RequestParam("uid") String  fileName){

        return fileUpLoadService.delete(fileName);
    }
}
